deserializer_01=function()
{
}

/** @private **/
deserializer_01.prototype.type="XMLDeserializer_01";

/**
 * Return the draw2d document as XML
 *
 * @param {Document} document The Draw2D document
 * @type String
 * @see ToolSave
 **/
deserializer_01.prototype.fromXML=function(pp,workflow)
{

	var objects = new Array();
	var lines = new Array();
	for(var i=0;i< pp.length; i++)
	{
		if(pp[i].localName!="Connection"){
			objects.push(pp[i]); 
		}else{
			lines.push(pp[i]);
		}

	}

	for(var i=0;i< objects.length; i++ )
	{

		var node = objects[i];

		var x,y,id;
		for(var k=0;k<node.attributes.length;k++){
			var attrs = node.attributes[k];                       		
			if(attrs.name == "x"){
				x = attrs.value;
			}else if(attrs.name == "y"){
				y = attrs.value;
			}else if(attrs.name == "id"){
				id = attrs.value;
			}
		}
		if(node.localName=="Teacher"){
			var figure = new Teacher();
			figure.setId(id);
			workflow.addFigure(figure,x,y);
		}else if(node.localName=="Teachers"){
			var figure = new Teachers();
			figure.setId(id);
			workflow.addFigure(figure,x,y);
		}else if(node.localName=="Start"){
			var figure = new Start();
			figure.setId(id);
			workflow.addFigure(figure,x,y);
		}else if(node.localName=="OneToTwo"){
			var figure = new OneToTwo();
			figure.setId(id);
			workflow.addFigure(figure,x,y);
		}else if(node.localName=="TwoToOne"){
			var figure = new TwoToOne();
			figure.setId(id);
			workflow.addFigure(figure,x,y);
		}else if(node.localName=="Student"){
			var figure = new Student();
			figure.setId(id);
			workflow.addFigure(figure,x,y);
		}else if(node.localName=="Students"){
			var figure = new Students();
			figure.setId(id);
			workflow.addFigure(figure,x,y);
		}else if(node.localName=="Activity"){
			var figure = new Activity();
			figure.setId(id);
			workflow.addFigure(figure,x,y);
		}else if(node.localName=="SupportActivity"){
			var figure = new SupportActivity();
			figure.setId(id);
			workflow.addFigure(figure,x,y);
		}else if(node.localName=="Exit"){
			var figure = new Exit();
			figure.setId(id);
			workflow.addFigure(figure,x,y);
		}

	}

	var figures = workflow.getFigures();
	var drawedFigures = new Array();
	for(var i=0;i< figures.getSize(); i++)
	{
			drawedFigures[i]=figures.get(i);
	}

	var targetNode,sourceNode;
	var flagSource,flagTarget;
	for(var i=0;i< lines.length; i++ ){
		var node = lines[i];
		var sourceParentNodeId,targetParentNodeId;
		sourceParentNodeId = node.attributes[0].value;
		targetParentNodeId = node.attributes[1].value;
		
		if(i>0){
			if(sourceParentNodeId==sourceNode){
				flagSource=true;
				console.log(flagSource+" flagSource");
			}
			if(targetParentNodeId==targetNode){
				flagTarget=true;
				console.log(flagTarget+" flagTarget");
			}
			
		}

		var c = new ContextmenuConnection();
		var counter = 0;
		while(c.getSource()== null ||  c.getTarget()== null){
			var figure = drawedFigures[counter];
			
			if(figure.id==sourceParentNodeId){
				if(flagSource){
					c.setSource(figure.getPort("outputPort1"));
				}else{
					c.setSource(figure.getPort("outputPort"));
				}
			}else if(figure.id==targetParentNodeId){
				if(flagTarget){
					c.setTarget(figure.getPort("inputPort1"));
				}else{
					c.setTarget(figure.getPort("inputPort"));
				}
			}
			if(c.getSource()!= null &&  c.getTarget()!= null){
				workflow.addFigure(c);
				window.onscroll=function(){workflow.onScroll();}
			}
			counter++;
		}
		targetNode=targetParentNodeId;
		sourceNode=sourceParentNodeId;
		flagSource=false;
		flagTarget=false;
	}
}